<?php
/**
 * Created by PhpStorm.
 * User: zq
 * Date: 2017/3/6
 * Time: 12:17
 */

namespace Home\Model;


use Common\Model\BaseModel;


class LoginModel extends BaseModel
{
    public function login(){
        $username = I('post.username');
        $password = I('post.password');
        $code = I('post.code');
        $data = M('login')->find();
//      dump($data);die;
        if($data['username']!=$username){
            $this->error = '用户名不存在';
            return false;
        }
        if($data['password'] !=$password){
            $this->error ='密码不正确';
            return false;
        }
        if(!$this->check_verify($code)){
            $this->error ='验证码错误';
            return false;
        }
        session('name',$username);
        session('uid',$data['uid']);
//        print_r($_SESSION);die;
        return true;
    }

    function check_verify($code, $id = '')
    {
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }
    public function reg(){
         $data =I('post.');
//        p($data);die;
//        $this->store(new LoginModel(),$data,function(){
//            $this->success('操作成功',u('index'));die;
//        });
        if($this->create()){
           if($this->add($data)){
               return true;
           } else{
               return false;
           }
        }


    }


}